IDA consistent IC: dae_init_mode, battery hold, forcing t+, source currents - #3845
Open
nrnhines wants to merge 24 commits into
Open
IDA consistent IC: dae_init_mode, battery hold, forcing t+, source currents#3845nrnhines wants to merge 24 commits into
nrnhines wants to merge 24 commits into
Conversation
Add dae_init_mode(0|1|2) to select legacy nano-step heuristic (default), IDACalcIC(IDA_Y_INIT) with heuristic fallback, or pure IDA_Y_INIT. Soft-fail sparse factor errors during CalcIC so mode 1 can fall back cleanly. Document and test pure algebraic LinearMechanism success and series C-R fallback.
…acitors Replace capacitive couplings with voltage-source constraints that hold branch Δv and solve the augmented G/B algebraic system. Falls back to the nano-step heuristic only on failure. Includes unit test for series C–R current step and docs for mode 3.
Classify C structure: floating caps keep Δv battery stamps; diagonal mass holds inductor current; one-sided C (OpAmp tau*vk') holds output voltage and drops the dynamic equation. Add unit tests for op-amp continuous hold and inductor current hold under dae_init_mode(3).
Hold continuous Vm and xc layer content via stiff springs on the resistive (cj=0) matrix, then restore holds exactly (allowing algebraic common-mode when outer xc is zero). Wire into Daspk battery init after LinearMechanism projection and add a cable+extracellular smoke test.
Diagnostic dump of residual/state before discontinuity, after event, and after re-init. Arm with dae_init_audit(level, t) for first reinit at or after t; write to stdout or a file via dae_init_audit_file. Panel A uses the continuous residual captured at integrator retreat (interpolate after a step that may overshoot), with continuous play synchronized to the event time—shared by Vector.play, NetCon, and at_time—not a re-evaluation after the jump or the raw step endpoint.
Status, architecture, build/test notes, and a starting prompt for new Grok sessions on hines-grok/ida-init in ~/neuron/nrnida.
Recover continuous y' from the mass equation at fixed projected y instead of the dteps nano-step companion, so residual WRMS can reach zero on stiff cases (e.g. SEClamp + tiny cm). Keep nano-step only as residual fallback; classify algebraic vs near-singular residual eqs on failure; suppress fallback when an IC audit is armed. Document and test.
Add nrn_vecplay_continuous_tplus matching VecPlayContinuous interpolate geometry (outgoing slope at knots; linear extrapolation of the last two points past the end). Expose VecPlayContinuous::forcing_tplus for later IC use. Document forcing t+ info (1-jet) in cvode.rst and GROK-IDA-INIT; unit tests for slope extraction oracles.
At each Daspk::init, sample all VecPlayContinuous instances for right-limit u and classical u' (forcing t+ info / 1-jet), store on Daspk for A2, and list them in the three-panel IC audit. Add ramp-play hoctest checking u≈0.5 and u'≈0.5 after the t=1 jump onto the ramp segment.
After C*y'=b-Gy particular seed, adjust y' in null(C) so left-null constraints Z'G y' = Z'b' hold, with b' from Vector.play slopes mapped into LinearMechanism b. Fixes series C–R ramp IC (V1'=1, V2'=0.5 when I=0.5, I'=0.5, R=C=1) without a nano-step.
Add series C–R integration tests for step, slope kink, post-end extrapolation, flat hold, finitialize first-segment slope, and two-event iramp-like sequence. Treat t=t0 as outgoing slope for forcing t+ (strict hold only for t<t0) so finitialize ramps get the correct I'.
Add lm.dforce(callable, bdot) so non-play forcing can supply db/dt for mode-3 free y' completion. Callable runs at IC time; optional FD of the force callable when dforce is unset. Audit lists LM dforce/bdot/fd entries. Tests: sinusoid analytic and FD fallback on series C–R.
Track mode-3 success/fallback and free-y' sources (play, dforce, FD). Expose CVode.dae_init_stats() for print/reset/Vector fill; include in statistics(). Audit notes list free-y' sources; fallback messages name mode 3 vs nano-step explicitly.
Add piecewise-linear electrode stimulus (test-only) and mode-3 coverage for IClamp/PWL istep, kink, jump-ramp, and E0 Section vs LM play parity. Update GROK-IDA-INIT for (b) in progress and parked density dforce.
Re-ran test_ida_init_mode.py and isolated A1 ramp + A3 istep/kink suite under mode 3; no code changes. Handoff notes WP2 done; next is WP3.
…i tests. Coupled C y'=f seeding now puts electrode current into extracellular mass (1-layer and multi-layer cumulative F), so mode 3 clears residual for IClamp/PWL steps with extracellular. Add E1 Section/LM parity and Z0/Z1 LM end-ri() twins; cable zero-area end inject still may nano-step fallback.
Note hoctests::test_ida_source_current (PWLClamp via nrnivmodl hash) and standalone run instructions; handoff points at C→A→B stack.
Add nrn_cable_battery_ic: hold CAP-list node voltages, free section-end nodes so electrode at loc 0/1 can set absolute levels; soft-fail if the cj=0 factor is singular. Pre-evaluate residual so BREAKPOINT/at_time sees t+ before project. Extracellular Vm holds skip zero-area nodes. Tests require path_mode=3 for end IClamp/PWL and Z0/Z1 Section+LM.
E2 xc=0 resistive xtral istep (path_mode 3); E3 multi-layer xc>0 istep; E4 weak/strong xg istep with Vm hold. Completes WP3 topology matrix for mid-compartment electrode sources.
Expand CVode.dae_init_mode documentation for electrode sources, at_time, extracellular Vm vs vext, and play/dforce 1-jet use. Fix E2/E* tests to treat seg.v as transmembrane Vm (vext may jump when xc=0). Handoff notes nrndc1sim smoke: mode 3 at finitialize; transfer re_init often falls back.
|
✔️ a15e968 -> Azure artifacts URL |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3845 +/- ##
==========================================
+ Coverage 68.34% 68.72% +0.37%
==========================================
Files 701 704 +3
Lines 112265 113470 +1205
==========================================
+ Hits 76731 77978 +1247
+ Misses 35534 35492 -42 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
✔️ a15e968 -> artifacts URL |
UBSan aborted LinearMechanism construction: NrnDAE bound references to optional-null elayer and y0 Vectors. Defer those dereferences until the pointers are known non-null. macOS ASan/TSan aborted isolated python -c children because SIP drops DYLD_INSERT_LIBRARIES. Re-apply NRN_SANITIZER_PRELOAD_* (same pattern as test_basic.py) so interceptors load before dlopen of libnrniv.
|
|
✔️ a108b2a -> Azure artifacts URL |
Contributor
|
✔️ a108b2a -> artifacts URL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Adds optional consistent initialization for the IDA (DASPK) path when models have algebraic constraints, LinearMechanism networks, extracellular capacitance, and discontinuous source currents (steps / PWL /
Vector.play).CVode.dae_init_mode(0–3) — default remains 0 (nano-step heuristic). Mode 1/2 useIDACalcIC; mode 3 holds continuous content (LM battery + extracellular / cable) then sets (y') from (C y' = f(y)). Residual failure falls back to the heuristic (unless the three-panel audit is armed).Vector.playat reinit; free LM (y') completed from play,LinearMechanism.dforce, or FD off_callable.dae_init_auditthree-panel dump, IC path stats, residual classification on mode-3 failure.CVode.dae_init_mode/ electrode notes incvode.rst; LMdforceinlinmod.rst.test_ida_init_mode.py,test_ida_source_current.py(E0–E4, ends, Z*, A3/A4 forcing), unitvecplay_tplus, PWLClamp MOD,ctest -R hoctests::test_ida_(init_mode|source_current).Also includes working handoff
GROK-IDA-INIT.md(session notes; density MODdforceremains parked on a separate branch).Test plan
ctest -R 'hoctests::test_ida_(init_mode|source_current)'(and related IDA suites as available)ninja cover-diffwithNRN_ENABLE_COVERAGE+ listed files)